

from apps.evaluation.models import Evaluation_List, SmartLifeSupportCenter_BranchOffice, \
    DigitalIntelligence_Branch_office, SmartLifeSupportCenter_BusinessDepartment, DigitalIntelligence_BusinessDepartment
from django_filters.rest_framework import FilterSet
from django_filters import rest_framework as filters, CharFilter

from apps.system.models import User


class Evaluation_ListFilter(FilterSet):
    """
    Evaluation_List过滤
    """
    # has_reviewer = filters.BooleanFilter(method="filter_has_reviewer")
    class Meta:
        model = Evaluation_List
        fields = ['evaluation_period','evaluation']

    # def filter_has_reviewer(self, queryset, name, value):
    #     current_user = self.request.user
    #     if value:
    #         return queryset.filter(evaluation__model__evaluation_item__reviewer=current_user)
    #     else:
    #         return queryset.exclude(evaluation__model__evaluation_item__reviewer=current_user)



class Evaluation_ManageFilter(FilterSet):
    """
    Evaluation_Manage过滤
    """
    # has_reviewer = filters.BooleanFilter(method="filter_has_reviewer")
    class Meta:
        model = Evaluation_List
        fields = ['evaluation_period','evaluation']


class SmartLifeSupportCenter_BranchOfficeFilter(FilterSet):
    """
    SmartLifeSupportCenter_BranchOffice过滤
    """
    evaluation_item_id = CharFilter(field_name="evaluation_item", help_text="参评项目id", lookup_expr="exact")
    class Meta:
        model = SmartLifeSupportCenter_BranchOffice
        fields = ['evaluation_item_id','reviewer']

class DigitalIntelligence_Branch_officeFilter(FilterSet):
    """
    DigitalIntelligence_Branch_office过滤
    """
    evaluation_item_id = CharFilter(field_name="evaluation_item", help_text="参评项目id", lookup_expr="exact")
    class Meta:
        model = DigitalIntelligence_Branch_office
        fields = ['evaluation_item_id','reviewer']


class SmartLifeSupportCenter_BusinessDepartmentFilter(FilterSet):
    """
    SmartLifeSupportCenter_BusinessDepartment过滤
    """
    evaluation_item_id = CharFilter(field_name="evaluation_item", help_text="参评项目id", lookup_expr="exact")
    class Meta:
        model = SmartLifeSupportCenter_BusinessDepartment
        fields = ['evaluation_item_id','reviewer']


class DigitalIntelligence_BusinessDepartmentFilter(FilterSet):
    """
    DigitalIntelligence_BusinessDepartment过滤
    """
    evaluation_item_id = CharFilter(field_name="evaluation_item", help_text="参评项目id", lookup_expr="exact")
    class Meta:
        model = DigitalIntelligence_BusinessDepartment
        fields = ['evaluation_item_id','reviewer']

class Evaluation_SituationFilter(FilterSet):
    """
    Evaluation_SituationFilter过滤
    """
    evaluation_item_id = CharFilter(field_name="evaluation_authorities", help_text="参评权限", lookup_expr="icontains")
    class Meta:
        model = User
        fields = ['evaluation_item_id']



__all__ =[
    'Evaluation_ListFilter',
]
